<?php
// +----------------------------------------------------------------------
// | 07FLYSAAS [基于ThinkPHP5.0开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2025-2035 http://www.07fly.xyz
// +----------------------------------------------------------------------
// | Professional because of focus  Persevering because of happiness
// +----------------------------------------------------------------------
// | Author: 开发人生 <goodkfrs@qq.com>
// +----------------------------------------------------------------------


namespace app\plat\model;

/**
 * Admin基础模型
 */
class Login extends PlatModelBase
{

    public function getLoginInfo($uid, $tid)
    {
        $this->modelTenUser->setIgnoreTenantCheck(true);
        $user = $this->modelTenUser->getInfo(['id' => $uid], '*');
        if (!empty($user)) {
            $user = $user->toArray();
            $auth = ['ten_user_id' => $user['id'], TIME_UT_NAME => TIME_NOW];
            session('ten_user_info', $user);
            session('ten_user_auth', $auth);
            session('ten_user_auth_sign', data_auth_sign($auth));
        }

        $this->modelTenTenant->setIgnoreTenantCheck(true);
        $tenantInfo = $this->modelTenTenant->getInfo(['id' => $tid], '*');
        if (!empty($tenantInfo)) {
            if ($tenantInfo['visible'] != '1') {
                throw_response_error('租户已禁用');
            }
            $tenantInfo = $tenantInfo->toArray();
            $auth = ['ten_tenant_id' => $tenantInfo['id'], 'init_admin_id' => $tenantInfo['init_admin_id'], TIME_UT_NAME => TIME_NOW];
            session('ten_tenant_info', $tenantInfo);
            session('ten_tenant_auth', $auth);
            session('ten_tenant_auth_sign', data_auth_sign($auth));
        }
    }

}
